package sklad;

/**
 * User: Vladimir
 * Date: 23.09.12 Time: 18:56
 */
public class GoodItem implements Cloneable {
    public String article;
    public String category;
    public String name;
    public int count;
    public int sellCount;
    public double buyPrice;
    public double sellPrice;
    public SourceEnum supplier = SourceEnum.UNKNOWN;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        GoodItem goodItem = (GoodItem) o;

        if (article != null ? !article.equals(goodItem.article) : goodItem.article != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return article != null ? article.hashCode() : 0;
    }

    @Override
    public String toString() {
        return "GoodItem{" +
                "article='" + article + '\'' +
                ", name='" + name + '\'' +
                ", count=" + count +
                ", sellCount=" + sellCount +
                ", buyPrice=" + buyPrice +
                ", sellPrice=" + sellPrice +
                ", supplier='" + supplier.name + '\'' +
                '}';
    }

    public static GoodItem copyItem(GoodItem item) {
        GoodItem newItem = new GoodItem();
        newItem.article = item.article;
        newItem.name = item.name;
        newItem.count = item.count;
        newItem.sellCount = item.sellCount;
        newItem.buyPrice = item.buyPrice;
        newItem.sellPrice = item.sellPrice;
        newItem.supplier = item.supplier;
        return newItem;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        GoodItem item = new GoodItem();
        item.sellPrice = sellPrice;
        item.buyPrice = buyPrice;
        item.category = category;
        item.article = article;
        item.name = name;
        item.count = count;
        item.sellCount = sellCount;
        item.supplier = supplier;
        return item;
    }
}
